package com.ct.entity.po;

import java.io.Serializable;
import java.util.Date;

import lombok.Builder;
import org.springframework.format.annotation.DateTimeFormat;

import com.ct.entity.enums.DateTimePatternEnum;
import com.ct.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 用户表
 */
@Builder
public class User implements Serializable {

    /**
     * 用户编号
     */
    private String userId;

    /**
     * 登录密码
     */
    private String password;

    /**
     * 用户姓名
     */
    private String name;

    /**
     * 性别，男，女
     */
    private String sex;

    /**
     * 出生日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 联系方式
     */
    private String phone;

    /**
     * 邮箱
     */
    private String email;

    /**
     * 职位
     */
    private String position;

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserId() {
        return this.userId;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return this.password;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getSex() {
        return this.sex;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Date getBirthday() {
        return this.birthday;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return this.email;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getPosition() {
        return this.position;
    }

    @Override
    public String toString() {
        return "用户编号:" + (userId == null ? "空" : userId) + "，登录密码:" + (password == null ? "空" : password) + "，用户姓名:"
                + (name == null ? "空" : name) + "，性别，男，女:" + (sex == null ? "空" : sex) + "，出生日期:"
                + (birthday == null ? "空" : DateUtil.format(birthday, DateTimePatternEnum.YYYY_MM_DD.getPattern()))
                + "，联系方式:" + (phone == null ? "空" : phone) + "，邮箱:" + (email == null ? "空" : email) + "，职位:"
                + (position == null ? "空" : position);
    }

    User(String userId, String password, String name, String sex, Date birthday, String phone, String email, String position) {
        this.userId = userId;
        this.password = password;
        this.name = name;
        this.sex = sex;
        this.birthday = birthday;
        this.phone = phone;
        this.email = email;
        this.position = position;
    }

    public static UserBuilder builder() {
        return new UserBuilder();
    }

    public static class UserBuilder {
        private String userId;
        private String password;
        private String name;
        private String sex;
        private Date birthday;
        private String phone;
        private String email;
        private String position;

        UserBuilder() {
        }

        public UserBuilder userId(String userId) {
            this.userId = userId;
            return this;
        }

        public UserBuilder password(String password) {
            this.password = password;
            return this;
        }

        public UserBuilder name(String name) {
            this.name = name;
            return this;
        }

        public UserBuilder sex(String sex) {
            this.sex = sex;
            return this;
        }

        @JsonFormat(
                pattern = "yyyy-MM-dd",
                timezone = "GMT+8"
        )
        public UserBuilder birthday(Date birthday) {
            this.birthday = birthday;
            return this;
        }

        public UserBuilder phone(String phone) {
            this.phone = phone;
            return this;
        }

        public UserBuilder email(String email) {
            this.email = email;
            return this;
        }

        public UserBuilder position(String position) {
            this.position = position;
            return this;
        }

        public User build() {
            return new User(this.userId, this.password, this.name, this.sex, this.birthday, this.phone, this.email, this.position);
        }

        public String toString() {
            return "User.UserBuilder(userId=" + this.userId + ", password=" + this.password + ", name=" + this.name + ", sex=" + this.sex + ", birthday=" + this.birthday + ", phone=" + this.phone + ", email=" + this.email + ", position=" + this.position + ")";
        }
    }
}
